//
//  LAMerchantDetailViewController.m
//  LYLazizDevelopDemo
//
//  Created by xbn_iMac on 2016/10/21.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LAMerchantDetailViewController.h"
#import "AppDelegate.h"
#import "LAMerchantDetailTableView.h"
#import "UIViewController+NavigationItemSetting.h"
#import "UINavigationController+FDFullscreenPopGesture.h"
#import "LAWriteReviewViewController.h"
#import "LAMerchantDetailVideoTableView.h"
#import "LAMerchantDetailReviewTableView.h"
#import "LAMerchantPhotoTableView.h"
#import "LAMerchantInformationTableView.h"
#import "LZCheckoutView.h"
#import "LZRestaurantDetailBottomButton.h"
#import "LZActionSheet.h"
#import "UIView+Rotation.h"
#import "UIButton+TransitionEdgeInsets.h"
#import "LZMapViewController.h"
#import "LZVideoCellPresenter.h"
#import "LZRestaurantDetailModel.h"
#import "LZRestaurantPresenter.h"
#import "LZUserOperationPresenter.h"
#import "LZUserModel.h"
#import "LZLoginViewController.h"
#import "LZZanAndCollectStatusPresenter.h"
#import "LZCheckCouponAndGrouponPresenter.h"
#import "LZMapModel.h"
#import "TShareView.h"
#import "TShareEventHandler.h"
#import "LZAlertView.h"
#import "LZRemindView.h"

@interface LAMerchantDetailViewController ()<LAMerchantDetailTableViewDelegate,SubTableViewDelegate,LZVideoCellDelegate,RestaurantReviewTableViewDelegate,PromotionPayDelegate>

@property (weak, nonatomic) IBOutlet UIView *bottomView;
@property (weak, nonatomic) IBOutlet LZRestaurantDetailBottomButton *btnCollect;
@property (weak, nonatomic) IBOutlet LZRestaurantDetailBottomButton *btnReview;
@property (weak, nonatomic) IBOutlet UIButton *btnPay;
@property (weak, nonatomic) IBOutlet LAMerchantDetailTableView *mainTableView;
@property (strong, nonatomic) LZRestaurantDetailModel *model;
@property (strong, nonatomic) UIButton *nav_left_back;
@property (strong, nonatomic) UIButton *nav_right_share;
@property (assign, nonatomic) CGFloat navbar_change_y;
@property (weak, nonatomic) LZActionSheet * sheetView;

@property (assign, nonatomic) CGFloat lzAlpha;

@property (nonatomic, strong) LZVideoCellPresenter *videoCellPresenter;

@property (nonatomic, weak) LZCheckoutView *couponView;

@property (nonatomic, strong) TShareView * shareView;

@end

@implementation LAMerchantDetailViewController

-(void)viewDidLoad {
    [super viewDidLoad];
    
    self.umLogPageViewName = @"商户详情页面";
    
    self.mainTableView.detailDelegate = self;
    self.navbar_change_y = SCREEN_WIDTH/375.0*(500-40)/2.0-64;
    [self configNavigationBar];
    
    [self configTableViewsDelegate];
    
    // 点评餐厅(按钮)
    [self.btnReview setTitle:LZLocalizedString(@"review_write", nil) forState:UIControlStateNormal];
    // 优惠买单(按钮)
    [self.btnPay setTitle:LZLocalizedString(@"restaurant_pay_coupon", nil) forState:UIControlStateNormal];
    
    [self requestRestaurantDetailInfo];
    [self hideSubviews];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

-(void)viewDidAppear:(BOOL)animated {
    
    [super viewDidAppear:animated];
    [self.mainTableView viewShow];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.mainTableView viewDiss];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [self.mainTableView.videoTable stopPlayVideo];
}

- (BOOL)fd_prefersNavigationBarHidden {
    return YES;
}

#pragma mark - request method

// 餐厅--详细信息
- (void)requestRestaurantDetailInfo {

    WS(weakSelf)
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:NO];
    [LZRestaurantPresenter getRestaurantDetailWithRestaurantID:self.restaurantId ResultSuccess:^(id result) {
        [weakSelf stopLoadingViewForView:weakSelf.view];
        [weakSelf showSubviews];
        LZRestaurantDetailModel *model = (LZRestaurantDetailModel*)result;
        weakSelf.mainTableView.model = model;
        weakSelf.model = model;
        UIImage *image = model.isStore?[UIImage imageNamed:@"restaurant_detail_bottom_collect"]:[UIImage imageNamed:@"restaurant_detail_bottom_uncollect"];
        [weakSelf.btnCollect setImage:image forState:UIControlStateNormal];
    } ResultFailed:^(NSString *remind) {
        [weakSelf stopLoadingViewForView:weakSelf.view];
    }];
}

// 收藏/取消收藏
- (void)requestCollect:(BOOL)isCollect successBlock:(void(^)())successBlock{
    WS(weakSelf)
    [LZUserOperationPresenter collectOrCancelCollectVideoOrRestaurantWithSellerID:self.restaurantId PromotionID:nil FavoriteType:@"0" OperationType:[NSString stringWithFormat:@"%d",isCollect] ResultSuccess:^(NSInteger totleCount, NSInteger operationType) {
        DLog(@"-==-=====收藏成功");
        [[LZZanAndCollectStatusPresenter shareInstance] addCollectRsetaurantWithId:weakSelf.restaurantId andCollectStatus:isCollect];
        
        if (successBlock) {
            successBlock();
        }
    } ResultFailed:^(NSString *remind) {
        DLog(@"%@",remind);
    }];
    
    
   
}

// 餐厅--优惠视频列表
- (void)requestRestaurantVideoWithPrameter:(NSDictionary*)prameter andPage:(int)page andLimit:(int)limit resultSuccess:(void (^)(NSArray *,NSNumber*))successBlock {
    [LZRestaurantPresenter getRestaurantDetailVideoListWithPrameter:prameter RestaurantID:self.restaurantId PageNum:page PageLimit:limit ResultSuccess:^(NSArray *listArr,NSNumber *timeStemp) {
        if (successBlock) {
            successBlock(listArr,timeStemp);
        }
    } ResultFailed:^(NSString *remind) {
        if (successBlock) {
            successBlock(nil,nil);
        }
    }];
    
}

// 餐厅--评论数量统计
- (void)requestCommentCountSuccess:(void (^)(id))successBlock {
    [LZRestaurantPresenter getRestaurantCommentTotleNumWithRestaurantID:self.restaurantId ResultSuccess:^(id result) {
        if (successBlock) {
            successBlock(result);
        }
    } ResultFailed:^(NSString *remind) {
        if (successBlock) {
            successBlock(nil);
        }
    }];
}

// 餐厅--评论列表
- (void)requestRestaurantReviewListWithPrameter:(NSDictionary*)prameter andPage:(int)page andLimit:(int)limit resultSuccess:(void (^)(NSArray *,NSNumber *))successBlock{
    
    // 评论类型（0全部，1好评，2差评，3有图；不填为全部）
    [LZRestaurantPresenter getRestaurantDetailCommentListWithPrameter:prameter RestaurantID:self.restaurantId PageNum:page PageLimit:limit ResultSuccess:^(NSArray *listArr,NSNumber *timeStemp) {
        if (successBlock) {
            successBlock(listArr,timeStemp);
        }
        
    } ResultFailed:^(NSString *remind) {
        if (successBlock) {
            successBlock(nil,nil);
        }
    }];
}

// 获取餐厅相册
- (void)requestRestaurantPhotoAlbumWithPrameter:(NSDictionary*)prameter andPage:(int)page andLimit:(int)limit resultSuccess:(void (^)(NSArray *,NSNumber *))successBlock {
    [LZRestaurantPresenter getRestaurantPhotoAlbumWithRestaurantID: self.restaurantId  /*  @"f83065fe529449ab8dc72480b490d468"  */ ResultSuccess:^(NSArray *result) {
        if (successBlock) {
            successBlock(result,nil);
        }
    } ResultFailed:^(NSString *remind) {
        if (successBlock) {
            successBlock(nil,nil);
        }
    }];
}

// 餐厅--餐厅列表
- (void)requestRestaurantListWithPrameter:(NSDictionary*)prameter andPage:(int)page andLimit:(int)limit resultSuccess:(void (^)(NSArray *,NSNumber *))successBlock {
    
    [LZRestaurantPresenter getRestaurantListWithFilterPrameter:@{@"mapLocationLongitude":[NSNumber numberWithDouble:self.model.mapLocationLongitude],@"mapLocationLatitude":[NSNumber numberWithDouble:self.model.mapLocationLatitude]} PageNum:page pageLimit:limit ResultSuccess:^(NSMutableArray *listArr,int nowPage,NSTimeInterval timestamp) {
        NSArray *result = [listArr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self.restaurantId = %@",self.model.restaurantId]];
        if (result.count > 0) {
            [listArr removeObject:result[0]];
        }
        if (successBlock) {
            successBlock(listArr,nil);
        }
    } ResultFailed:^(NSString *remind) {
        if (successBlock) {
            successBlock(nil,nil);
        }
    }];
}

// 优惠买单列表
- (void)requestUserPromotionListWithPrameter:(NSDictionary*)prameter resultSuccess:(void (^)(NSArray *))successBlock {
    [LZRestaurantPresenter getRestaurantPromotionListWithRestaurantID:self.restaurantId ResultSuccess:^(NSArray *result) {
        if (successBlock) {
            successBlock(result);
        }
    } ResultFailed:^(NSString *remind) {
        if (successBlock) {
            successBlock(nil);
        }
    }];
}

#pragma
#pragma mark public method
// 处理推送
- (BOOL)checkAndDealNotificaton:(NSDictionary*)notificationDic {
    if (_couponView) {
        
        NSDictionary *extra = notificationDic[@"extras"];
        [self.couponView scanQRCodeSuccessWithSellerId:extra[@"sellerId"] andPromotionId:extra[@"promotionId"] andNoRemarkId:extra[@"noRemarkId"]];
        
        return YES;
    }
    else {
        return NO;
    }
}

#pragma
#pragma mark private method

- (void)hideSubviews {
    self.mainTableView.hidden = YES;
    self.bottomView.hidden = YES;
}

- (void)showSubviews {
    self.mainTableView.hidden = NO;
    self.bottomView.hidden = NO;
}

-(void)configNavigationBar{
    
    self.nav_left_back = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nav_left_back.frame = CGRectMake(0, 0, 60, 40);
    [self.nav_left_back addTarget:self action:@selector(navbarBackButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    UIImage *image_back = [UIImage imageNamed:@"navigationbar_back_circle"];
    self.nav_left_back.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, CGRectGetWidth(self.nav_left_back.bounds)-image_back.size.width);
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0) {
        [self.nav_left_back setLanguageRotaion];
    }

    
    self.nav_right_share = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nav_right_share.frame = CGRectMake(0, 0, 40, 40);
    [self.nav_right_share addTarget:self action:@selector(navbarShareButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    UIImage *image_share = [UIImage imageNamed:@"share_icon_circle"];
    [self.nav_right_share setNormalImageEdgeInsets:UIEdgeInsetsMake(0, CGRectGetWidth(self.nav_right_share.bounds)-image_share.size.width, 0, 0)];

    [self setNavigationBarButtonImageWithNavigationBarAlpha:YES];

    
    [self hiddenBarNavigationItemSetting:@[self.nav_left_back] type:NAVIGATIONITEMSETTING_LEFT];
    
    [self hiddenBarNavigationItemSetting:@[self.nav_right_share] type:NAVIGATIONITEMSETTING_RIGHT];

    [self lz_setCustomBarAlpha:self.lzAlpha];
    
}

// 根据导航栏的透明值设置导航栏按钮图片
- (void)setNavigationBarButtonImageWithNavigationBarAlpha:(BOOL)isAlpha {
    
    [self.nav_left_back setImage:isAlpha?[UIImage imageNamed:@"navigationbar_back_circle"]:[UIImage imageNamed:@"navigationbar_back"] forState:UIControlStateNormal];
    
    [self.nav_right_share setImage:isAlpha?[UIImage imageNamed:@"share_icon_circle"]:[UIImage imageNamed:@"share_icon"] forState:UIControlStateNormal];
}

- (void)configTableViewsDelegate {
    self.mainTableView.videoTable.subTableDelegate = self;
    self.mainTableView.videoTable.videoDelegate = self;
    self.mainTableView.reviewTable.subTableDelegate = self;
    self.mainTableView.reviewTable.reviewTableDelegate = self;
    self.mainTableView.photoTable.subTableDelegate = self;
    self.mainTableView.informationTable.subTableDelegate = self;
    
    [self.mainTableView.videoTable checkHaveData];
}

#pragma
#pragma mark - event

-(void)navbarBackButtonClickAction:(UIButton*)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)navbarShareButtonClickAction:(UIButton*)sender {
    if (self.model == nil) {
        return;
    }
    
    WS(weakSelf)
    [self.shareView shareViewOpen];
    self.shareView.shareViewButtonActionBlock = ^(TSHAREVIEW_BUTTON_TYPE type){
        [weakSelf shareAction:type];
    };
}

// 收藏按钮
- (IBAction)collectButtonAction:(LZRestaurantDetailBottomButton *)sender {
    if ([[LZUserModel Instance] isLogin]) {
        if (self.model == nil) {
            return;
        }
        WS(weakSelf)
        [self requestCollect:!self.model.isStore successBlock:^{
            weakSelf.model.isStore = !weakSelf.model.isStore;
            UIImage *image = weakSelf.model.isStore?[UIImage imageNamed:@"restaurant_detail_bottom_collect"]:[UIImage imageNamed:@"restaurant_detail_bottom_uncollect"];
            [weakSelf.btnCollect setImage:image forState:UIControlStateNormal];
        }];
    }
    else {
        LZLoginViewController * vc = [[LZLoginViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

// 评价视频的按钮
- (IBAction)reviewButtonAction:(id)sender {
    if ([[LZUserModel Instance] isLogin]) {
        [self pushWriteReviewViewControllerWithType:WriteReviewType_Restaurant andSellerId:self.restaurantId andVideoId:nil andNoRemarkId:nil];
    }
    else {
        LZLoginViewController * vc = [[LZLoginViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

// 优惠买单
- (IBAction)payButtonAction:(id)sender {
    if ([[LZUserModel Instance] isLogin]) {
        if ([AppDelegate getDeviceToken]) {
            // 如果已经开了推送,则校验是否刚刚使用过优惠券
            WS(weakSelf)
            [LZCheckCouponAndGrouponPresenter checkUsedCouponAndGrouponResultSuccess:^(id result) {
                if (![result boolValue]) {
                    // 如果没使用过,则进入付款
                    [weakSelf.couponView showViewWithState:PayCouponViewState_SelectCoupon];
                    
                    // 禁用返回手势
                    weakSelf.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
                }
                else {
                    LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"restaurant_pay_short_time_remind", nil) andImage:nil cancelButtonTitle:nil otherButtonTitles:LZLocalizedString(@"confirm", nil),nil];
                    [alert show];
                }
            } ResultFailed:^(NSString *remind) {
                
            }];
            
        }
        else {
            // 如果没开推送，则提醒用户去开推送
            LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"iphone_permissions_notification_remind", nil) andImage:nil cancelButtonTitle:LZLocalizedString(@"cancel", nil) otherButtonTitles:LZLocalizedString(@"iphone_permissions_go_setting", nil),nil];
            [alert show];
            
            alert.clickButtonIndexBlock = ^(NSInteger index) {
                if (index == 1) {
                    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                }
            };
        }
    }
    else {
        LZLoginViewController * vc = [[LZLoginViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)pushWriteReviewViewControllerWithType:(WriteReviewType)type andSellerId:(NSString*)sellerId andVideoId:(NSString*)videoId andNoRemarkId:(NSString*)noRemarkId{
    
    if ([[LZUserModel Instance] isLogin]) {
        LAWriteReviewViewController *vc = [[LAWriteReviewViewController alloc] initWithNibName:@"LAWriteReviewViewController" bundle:nil] ;
        vc.type = type;
        vc.sellerId = [sellerId copy];
        if (videoId.length>0) {
            vc.videoId = [videoId copy];
        }
        if (noRemarkId.length>0) {
            vc.video_noRemarkId = [noRemarkId copy];
        }
        [self.navigationController pushViewController:vc animated:YES];
        
        WS(weakSelf)
        vc.uploadReviewBlock = ^(BOOL isUploadSuccess) {
            if (isUploadSuccess) {
                [weakSelf.mainTableView.reviewTable upData];
            }
        };
    }
    else {
        // 如果未登录
        LZLoginViewController * vc = [[LZLoginViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}

- (void)shareAction:(NSInteger)type {
    /* 分享餐厅 */
    SSDKPlatformType sharePlatformType = SSDKPlatformTypeUnknown;
    
    switch (type) {
        case 0:
            sharePlatformType = SSDKPlatformTypeSMS;
            break;
        case 1:
            sharePlatformType = SSDKPlatformTypeMail;
            break;
        case 2:
            sharePlatformType = SSDKPlatformTypeFacebook;
            break;
        case 3:
            sharePlatformType = SSDKPlatformTypeTwitter;
            break;
    }
    
    [TShareEventHandler shareWithShareURL:nil
                            shareImageUrl:@[[NSString stringWithFormat:@"%@%@",APIBaseImageUrl,self.model.sellerPhoto]]
                               shareTitle:[NSString stringWithFormat:LZLocalizedString(@"share_restaurant_title", nil),self.model.restaurantName]
                                shareText:[NSString stringWithFormat:LZLocalizedString(@"share_restaurant_content", nil),self.model.restaurantName,self.model.restaurantAddress,self.model.sellerPhoto]
                                shareType:sharePlatformType
                                  topView:nil
     stateBlock:^(SSDKResponseState state) {
         if (state == SSDKResponseStateSuccess) {
             [LZRemindView initWithImage:[UIImage imageNamed:@"提示对勾"] andContent:LZLocalizedString(@"share_success", nil)];
         }
         else if (state == SSDKResponseStateFail) {
             [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"] andContent:LZLocalizedString(@"share_fail", nil)];
         }
         else if (state == SSDKResponseStateCancel) {
             [LZRemindView initWithImage:[UIImage imageNamed:@"error_image"] andContent:LZLocalizedString(@"share_fail", nil)];
         }
     }];
    
    [self.shareView shareViewClose];
}

#pragma -
#pragma mark LAMerchantDetailTableViewDelegate
-(void)detailViewDidScroll:(UIScrollView *)scrollView {

    CGFloat offsetY = scrollView.contentOffset.y;

    if (offsetY <= self.navbar_change_y) {
        CGFloat alpha = MIN(1, offsetY/self.navbar_change_y);
        
        CGFloat navbar_item_alpha = fabs((alpha-0.5)/(0.5));
        self.nav_left_back.alpha = navbar_item_alpha;
        self.nav_right_share.alpha = navbar_item_alpha;
        if (alpha <= 0.5) {
            if (self.lzAlpha > 0.5) {
                [self setNavigationBarButtonImageWithNavigationBarAlpha:YES];
            }
        }
        else {
            if (self.lzAlpha <= 0.5) {
                [self setNavigationBarButtonImageWithNavigationBarAlpha:NO];
            }
        }
        self.lzAlpha = alpha;
        
    } else {
        self.lzAlpha = 1;
        if (self.nav_left_back.alpha<1) {
            self.nav_left_back.alpha = 1;
            self.nav_right_share.alpha = 1;
            [self setNavigationBarButtonImageWithNavigationBarAlpha:NO];
        }
    }
    
    [self lz_setCustomBarAlpha:self.lzAlpha];
}

- (void)detailViewCanNotScroll {
    self.lzAlpha = 1;
    if (self.nav_left_back.alpha<1) {
        self.nav_left_back.alpha = 1;
        self.nav_right_share.alpha = 1;
        [self setNavigationBarButtonImageWithNavigationBarAlpha:NO];
    }
}

- (void)showSheetView:(NSString*)phoneNumber {
    
    [self.sheetView ReloadTableViewArrayTitle:@[@[phoneNumber],@[LZLocalizedString(@"cancel", nil)]]];
    [self.sheetView ShowView];
}

#pragma mark RestaurantReviewTableViewDelegate
- (void)requestCommentCountResultSuccess:(void (^)(id))successBlock {
    [self requestCommentCountSuccess:successBlock];
}

#pragma mark - SubTableViewDelegate

-(void)requestDateWithType:(TableViewType)tableType andPrameter:(NSDictionary *)prameter andPage:(int)page andLimit:(int)limit resultSuccess:(void (^)(NSArray *,NSNumber*))successBlock {
    
    switch (tableType) {
        case TableViewType_Video:
        {
            [self requestRestaurantVideoWithPrameter:prameter andPage:page andLimit:limit resultSuccess:successBlock];
        }
            break;
        case TableViewType_Review:
        {
            [self requestRestaurantReviewListWithPrameter:prameter andPage:page andLimit:limit resultSuccess:successBlock];
        }
            break;
        case TableViewType_Photo:
        {
            [self requestRestaurantPhotoAlbumWithPrameter:prameter andPage:page andLimit:limit resultSuccess:successBlock];
        }
            break;
        case TableViewType_Information:
        {
            [self requestRestaurantListWithPrameter:prameter andPage:page andLimit:limit resultSuccess:successBlock];
        }
            break;
    }
}

- (void)tableViewType:(TableViewType)tableType didSelectRowAtIndexPath:(NSIndexPath *)indexPath object:(id)object {
    switch (tableType) {
        case TableViewType_Video:
        {

        }
            break;
        case TableViewType_Review:
        {
            
        }
            break;
        case TableViewType_Photo:
        {
            
        }
            break;
        case TableViewType_Information:
        {
            if (indexPath.section == 0) {
                if (indexPath.row == 1) {
                    [self checkMap];
                }
                else if (indexPath.row == 2) {
                    [self showSheetView:object];
                }
            }
            else if (indexPath.section == 1) {
                [self pushDetailView:object];
            }
        }
            break;
    }
}

#pragma mark -
#pragma mark video cell  delegate
/**
 cell 按钮协议方法
 index: 0点赞 1收藏  2信息  3分享   4更多  5抢券详情   6拼团详情
 */
- (void)clickCellButtonWithIndex:(VideoCellDelegateClickEventCode)index andCellIndexPath:(NSIndexPath *)cellIndexPath andModel:(id)model andOtherObject:(id)object refreshBlock:(void (^)(VideoCellRefreshType, BOOL))refreshBlock {
    [self.videoCellPresenter dealClickCellButtonIndex:index andCellIndexPath:cellIndexPath andNavigationController:self.navigationController andHidesBottomBarWhenPushed:NO andCellModel:model andOtherObject:object andRefreshBlcok:refreshBlock];
}

- (LZVideoCellPresenter*)videoCellPresenter {
    if (_videoCellPresenter) {
        return _videoCellPresenter;
    }
    
    _videoCellPresenter = [[LZVideoCellPresenter alloc] init];
    return _videoCellPresenter;
}

// 查看店家地址
- (void)checkMap {
    LZMapModel *mapModel = [[LZMapModel alloc] init];
    mapModel.longitude = self.model.mapLocationLongitude;
    mapModel.latitude = self.model.mapLocationLatitude;
    mapModel.title = self.model.restaurantName;
    mapModel.content = self.model.restaurantAddress;
    
    LZMapViewController *mapVC = [[LZMapViewController alloc]init];
    mapVC.restaurantModel = mapModel;
    [self.navigationController pushViewController:mapVC animated:YES];
}

// 拨打店家电话
- (void)callPhoto:(NSString*)phoneNumber {
    NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",[phoneNumber stringByReplacingOccurrencesOfString:@" " withString:@""]]];
    [[UIApplication sharedApplication] openURL:phoneURL];
}

// 进入店家详情
- (void)pushDetailView:(NSString*)restaurantId {
    LAMerchantDetailViewController *vc = [[LAMerchantDetailViewController alloc] init];
    vc.restaurantId = restaurantId;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - PromotionPayDelegate

- (void)requestPromotionDateWithPrameter:(NSDictionary *)prameter resultSuccess:(void (^)(NSArray *))successBlock {
    [self requestUserPromotionListWithPrameter:prameter resultSuccess:successBlock];
}

#pragma mark - 懒加载view 

- (LZCheckoutView*)couponView {
    if (_couponView) {
        return _couponView;
    }
    
    LZCheckoutView *v = [[LZCheckoutView alloc] initWithFrame:self.navigationController.view.bounds];
    v.promotionPayDelegate = self;
    [self.navigationController.view addSubview:v];
    
    WS(weakSelf)
    
    v.stateBlock = ^(PayCouponViewState state) {
        if (state == PayCouponViewState_Remove) {
            // 开启返回手势
            weakSelf.navigationController.fd_fullscreenPopGestureRecognizer.enabled = YES;
        }
    };
    
    v.reviewBlock = ^(NSString* sellerId,NSString *promotionId,NSString *noRemarkId) {
        [weakSelf pushWriteReviewViewControllerWithType:WriteReviewType_Video andSellerId:sellerId andVideoId:promotionId andNoRemarkId:noRemarkId];
    };
    
    _couponView = v;
    return _couponView;
}

- (LZActionSheet*)sheetView {
    if (_sheetView) {
        return _sheetView;
    }
    
    LZActionSheet *sheet = [[LZActionSheet alloc] initWithFrame:self.navigationController.view.bounds];
    _sheetView = sheet;
    [self.navigationController.view addSubview:_sheetView];
    
    WS(weakSelf)
    _sheetView.ClickSheetBlock = ^(NSIndexPath *indexPath, id obj) {
        if (indexPath.section == 0) {
            [weakSelf callPhoto:obj];
        }
    };
    
    return _sheetView;
}

- (TShareView *)shareView {
    
    if (_shareView == nil) {
        _shareView = [[TShareView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    }
    
    return _shareView;
}

@end

